//
// Created by itworker on 23-5-31.
//

#ifndef UDPPUNCHCLIENT_MSG_PROTOCOL_H
#define UDPPUNCHCLIENT_MSG_PROTOCOL_H

#include <list>

//定义iMessage Type
#define LOGIN       1   //client login
#define LOGOUT      2   //client logout
#define P2PTRANS    3   //Peer to Peer trans
#define GETALLUSER  4   //get all users info

//服务器 PORT
#define SERVER_PORT 9190

//客户端登录服务器时发送的消息体
struct cltLoginMessage
{
    char username[10];
    char password[15];
};

//客户端注销时发送的消息体
struct cltLogoutMessage
{
    char username[10];
};

//客户端向服务器请求让另一个客户端向自己发送UDP打洞信息
struct cltP2PTranslate
{
    char username[10];
};

//客户端向服务器发送的消息格式
struct cltMessage
{
    int iMessageType;
    union _message {
        cltLoginMessage     cltLoginMsg;
        cltLogoutMessage    cltLogoutMsg;
        cltP2PTranslate     cltTransMsg;
    }message;
};

//客户端节点信息
struct cltUserNode
{
    char username[10];
    unsigned int ip;
    unsigned short port;
};

//服务器向客户端发送的消息
struct servToClntMessage
{
    int iMessageType;
    union _message {
        cltUserNode cltUser;
    }message;
};


//======================================
// 下面的协议用于客户端之间的通信
//======================================
#define P2PMESSAGE              100 //send message
#define P2PMESSAGEACK           101 //ACK for message
#define P2PSOMEONEWANTTOCALLYOU 102 //server send message to client, wish the client to send a UDP punching packet
#define P2PTRASH                103 //client send UDP punching packet，the receiver ignore it

//客户端之间发送的消息格式
struct cltP2PMessage
{
    int iMessageType;
    int iStringLen;         //or IP address
    unsigned short Port;
};

//定义客户端节点池
typedef std::list<cltUserNode*> UserList;


#endif //UDPPUNCHCLIENT_MSG_PROTOCOL_H
